package com.atguigu.gmall.product.service.impl;

import com.atguigu.gmall.common.util.JSONs;
import com.atguigu.gmall.model.product.to.ValuesSkuJsonTO;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.atguigu.gmall.model.product.entity.SpuSaleAttr;
import com.atguigu.gmall.product.service.SpuSaleAttrService;
import com.atguigu.gmall.product.mapper.SpuSaleAttrMapper;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
* @author jiamin
* @description 针对表【spu_sale_attr(spu销售属性)】的数据库操作Service实现
* @createDate 2023-08-14 20:41:58
*/
@Service
public class SpuSaleAttrServiceImpl extends ServiceImpl<SpuSaleAttrMapper, SpuSaleAttr>
    implements SpuSaleAttrService{


    @Override
    public List<SpuSaleAttr> getSpuSaleAttrList(Long spuId) {
        return baseMapper.getSpuSaleAttrList(spuId);
    }

    @Override
    public List<SpuSaleAttr> getSpuSaleAttrListBySpuIdAndSkuId(Long skuId, Long spuId) {

        return baseMapper.getSpuSaleAttrListBySpuIdAndSkuId(skuId, spuId);
    }

    @Override
    public String getValuesSkuJsonTO(Long spuId) {
        List<ValuesSkuJsonTO> jsonTO = baseMapper.getValuesSkuJsonTO(spuId);
        Map<String, Long> map = jsonTO.stream().collect(Collectors.toMap(
                ValuesSkuJsonTO::getValuesSku,
                ValuesSkuJsonTO::getSkuId
        ));
        return JSONs.objecttoString(map);
    }
}




